﻿using Microsoft.Extensions.DependencyInjection;
using MyK3CloudCore.IOC.K3Client;
using System.Net;
using System.Net.Http;

namespace MyK3CloudCore.IOC;

public class K3Scoped
{
    public static K3CloudApiClient Client => GetK3CloudClient();
    public static CookieContainer Cookie => K3IOCServiceCollectionExtensions._cookie;
    public static IHttpClientFactory HttpFactory => K3IOCServiceCollectionExtensions.HttpClientFactory;
    private static K3CloudApiClient GetK3CloudClient()
    {
        var sugar = IocCallContext<K3CloudApiClient>.GetData(IocConst.CLIENT_KEY);
        if (sugar == null)
        {
            var result = K3CloudHelper.GetNewK3cloudClient();
            IocCallContext<K3CloudApiClient>.SetData(IocConst.CLIENT_KEY, result);
            return result;
        }
        else
        {
            return sugar;
        }
    }
}
